import App from './App'

/**
 * 全局存储
 */
// import store from './store/index'
// 时间戳转化时间
const getRelativeTime = (timestamp) => {
    const date = new Date(timestamp);

    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hours = date.getHours();
    const minutes = date.getMinutes();
    const seconds = date.getSeconds();

    const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; // 日期：2024-08-27
    // const formattedTime = formattedDate + ' ' + `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}`; 
    const formattedTime = formattedDate + ' ' + `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`; // 时间：16:35:28
    return formattedTime;
}

const getRelativeTimes = (timestamp) => {
    const date = new Date(timestamp * 1000);

    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hours = date.getHours();
    const minutes = date.getMinutes();
    const seconds = date.getSeconds();

    const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; // 日期：2024-08-27
    // const formattedTime = formattedDate + ' ' + `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}`; 
    const formattedTime = formattedDate + ' ' + `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`; // 时间：16:35:28
    return formattedTime;
}

// 引入全局工具函数
// import extenApi from './utils/extenApi'
// Vue.prototype.$extenApi = extenApi;

import tabBar from "./components/tabBar.vue"
import navBar from './components/navBar.vue'
import Nav from './components/nav.vue'
// 注册全局组件
Vue.component('tabBar', tabBar)
Vue.component('navBar', navBar)
Vue.component('Nav', Nav)

import { toast, modal } from "./utils/extenApi.js"

// 跳转url
function goto(pages){
	if(!pages){
		return toast({
			title:"功能暂未开通",
			icon:"error"
		})
	}
	uni.navigateTo({
		url:pages
	})
}

import share from './utils/share.js'; // 导入并挂载全局的分享方法

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
Vue.prototype.$getRelativeTime = getRelativeTime;
Vue.prototype.$getRelativeTimes = getRelativeTimes;
Vue.prototype.$goto = goto;
Vue.prototype.$toast = toast;
Vue.prototype.$modal = modal;
Vue.mixin(share);
App.mpType = 'app'
const app = new Vue({
	// store,
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif